package realm.inorder.i18n;

import java.text.MessageFormat;
import java.util.Locale;
import java.util.ResourceBundle;

import org.apache.log4j.Logger;

public enum Messages {
	
	WHATPANEL_TITLE("whatpanel.title"),
	WHATPANEL_DESCRIPTION("whatpanel.description"),
	
	HOWPANEL_TITLE("howpanel.title"),
	HOWPANEL_DESCRIPTION("howpanel.description"),
	
	REGISTERWINDOW_TITLE("registerwindow.title"),
	
	
	LOGINPANEL_TITLE("loginpanel.title"),
	LOGINPANEL_LOGIN_FIELD("loginpanel.loginfield"),
	LOGINPANEL_PASSWD_FIELD("loginpanel.passwdfield"),
	LOGINPANEL_LOGIN_BUTTON("loginpanel.loginbutton"),
	LOGINPANEL_REGISTER_BUTTON("loginpanel.registerbutton"),
	
	EMAIL_VALIDATION("email.validation"),
	TEXTFIELD_LENGTH_VALIDATION("textfield.length.validation");

	private static final Logger logger = Logger.getLogger(Messages.class);
	
	private String key;
	
	private static Locale locale = Locale.getDefault();

	private Messages(String key) {
		this.key = key;
	}
	
	static ResourceBundle resourceBundle;
	
	static {
		resourceBundle = ResourceBundle.getBundle("inorderMessages", locale);
	}
	
	public static String getBundleMessage(String key, Object ... format) {
		try {
			if (format == null) {
				return resourceBundle.getString(key);
			} else {
				String message = resourceBundle.getString(key);
				return MessageFormat.format(message, format);
			}
		} catch (Exception e) {
			logger.error("Error when getting message with key: "+key, e);
			return "Resource Bundle Message Error";
		}
	}
	
	public String getMessage(Object ... format) {
		return getBundleMessage(this.key, format);
	}

	@Override
	public String toString() {
		return getMessage();
	}

	public static Locale getLocale() {
		return locale;
	}

	public static void setLocale(Locale locale) {
		Messages.locale = locale;
	}
	
}
